package cn.yuhh.api.v1.declare;

import cn.yuhh.api.helper.ApiResponse;
import cn.yuhh.api.helper.IDataToMap;
import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.domain.DeclareInfo;
import cn.yuhh.core.domain.User;
import cn.yuhh.core.type.DeclareStatus;
import com.magic.spring.mongo.Mongo;
import org.bson.types.ObjectId;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author ysw
 * @create 2020-02-18 15:48
 * @descreption 根据用户角色获取不同代办列表
 *
 * yuhh
 **/
@Component("listDeclareService1.0")
public class ListDeclareService extends AbstractApiService {


    @Override
    public Map service(Map request) {
        //根据ID查操作员
        User manager = Mongo.buildMongo().eq("_id", new ObjectId(selfId(request))).findOne(User.class);
        //根据操作员角色和区域查表
        //todo 过滤角色环节
        List<DeclareInfo> declareInfos = Mongo.buildMongo().ne("declareStatus", DeclareStatus.end).or(new String[]{"mainManagerId","otherManagerId"}, new Object[]{selfId(request),selfId(request)},new String[]{"eq","eq"}).find(DeclareInfo.class);

        return ApiResponse.success(declareInfos, new IDataToMap<DeclareInfo>() {
            @Override
            public void dataToMap(Map map, DeclareInfo source) {
                map.put("selfId", selfId(request));
                source.list(map);
            }
        });
    }




}